﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HZ.Supervise.Web.PageControl
{
    public partial class MenuLeft : BasePage
    {

        HZ.Supervise.IBLL.IBLL_User ibllEntity = BLLFactory.BLL_User();

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            { 
                lblCurrentUser.Text = HZ.Supervise.Web.Function.GetNowTime() + "&nbsp;&nbsp;<img alt='' src='../Images/ModalImageAh_New/smile.gif'/>&nbsp;&nbsp;" + CurrentAccount.GetUser().UserName;
                //取得当前用户角色
                this.lblCurrentRole.Text = CurrentAccount.GetUser().Org.OrgName; 
            } 
        }

        /// <summary>
        /// 获取时段俗称
        /// </summary>
        /// <returns></returns>
        public string GetTimeSpanNick()
        {
            int hour = DateTime.Now.Hour;
            if (hour < 5)
            {
                return "凌晨";
            }
            else if (hour < 12)
            {
                return "上午";
            }
            else if (hour < 18)
            {
                return "下午";
            }
            else { return "晚上"; }
        }

        /// <summary>
        /// 通过菜单名称和用户编号查看是否有权限，如果没有权限隐藏菜单
        /// </summary>
        /// <param name="menuName"></param>
        /// <returns></returns>
        public string CheckMenuByUserID(string menuName)
        {
            Model.User user = CurrentAccount.GetUser();
            if (user.UserID == "jdjgqx")//如果是超级管理员，权限全开
            {
                if (menuName == "培训报名")//（新增合同、合同列表：区县）（培训报名：21市州），排除jdjg
                { 
                    return "display:none";
                }
                else
                {
                    return "";
                } 
            }
            else
            {
                string flag = "display:none";
                if (menuName == "培训查看" && user.Org.OrgID != "jdjgqx")//（培训查看，排除非中心账号）
                {
                    return "display:none";
                }
                string areaid = user.Org.Area.AreaID;
                if (menuName == "培训报名" && (!areaid.EndsWith("00") || user.Org.OrgID == "jdjgqx"))//（培训报名：21市州，排除区县、中心）
                {
                    return "display:none";
                }
                IList<HZ.Supervise.Model.OperatingRule> list = ibllEntity.GetUserOperatingRule(user.UserID);//得到该用户拥有的所有权限  
                foreach (HZ.Supervise.Model.OperatingRule itemMenu in list)//遍历
                { 
                    if (itemMenu.OperatingRuleName == menuName)//匹配
                    { 
                        flag = "";//存在的话，返回一个空字符串，菜单显示 
                        break;//终止循环 
                    } 
                } 
                return flag;
            }

        }
        /// <summary>
        /// 通过模块名称和用户编号查看是否有权限，如果没有权限隐藏整个模块
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public string CheckMenuByUserIDModule(string module)
        {
            if (CurrentAccount.GetUser().UserID == "jdjgqx")
            { 
                return ""; 
            }
            else
            {
                string areaid = CurrentAccount.GetUser().Org.Area.AreaID;
                if (module == "培训管理" && !areaid.EndsWith("00"))//（培训管理：排除区县）
                {
                    return "display:none";
                }
                IList<HZ.Supervise.Model.OperatingRule> list = ibllEntity.GetUserOperatingRule(CurrentAccount.GetUser().UserID);//得到该用户拥有的所有权限 
                string flag = "display:none"; 
                foreach (HZ.Supervise.Model.OperatingRule itemMenu in list)//遍历
                { 
                    if (itemMenu.Module.ToString() == module)//匹配
                    { 
                        flag = "";//存在的话，返回一个空字符串，菜单显示 
                        break;//终止循环 
                    } 
                } 
                return flag;
            } 
        }
    }
}
